﻿using System.Windows;
using System.Windows.Controls;
using MVVM.ViewModels;

namespace MVVM.Views
{
    /// <summary>
    /// Interaction logic for ListNames.xaml
    /// </summary>
    public partial class ListNames : UserControl
    {
        private Names names;
        public ListNames()
        {
            InitializeComponent();
            this.names = new Names();
            this.DataContext = this.names;
        }

        private void buttonAddName_Click(object sender, RoutedEventArgs e)
        {
            string newName = this.textBoxName.Text;
            if (string.IsNullOrEmpty(newName))
            {
                MessageBox.Show("Invalid Name");
                return;
            }

            this.names.AddName(newName);
            this.textBoxName.Text = string.Empty;
        }

        private void buttonDeleteName_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex = this.listBoxListNames.SelectedIndex;
            if (this.listBoxListNames.SelectedIndex >= 0)
            {
                this.names.DeleteName(this.names.NamesList[selectedIndex]);
            }
            else
            {
                MessageBox.Show("Please select name to delete");
            }
        }
    }
}
